@extends('admin.layout.layout')


@section('content')
   <div class="col-lg-12">
       <div class="panel panel-default">
        <div class="panel-heading">
           友情链接列表
        </div>
        <!-- /.panel-heading -->
         @if(session('error'))
              <div class="alert alert-danger alert-dismissable">
              <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                <ul>
                 <li> {{session('error')}}</li>
                   
                </ul>
            </div> 
         @endif
         @if(session('success'))
            <div class="alert  alert-success alert-dismissable">
              <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                <ul>
                 <li> {{session('success')}}</li>
                   
                </ul>
            </div> 
         @endif

            <div class="panel-body">
                <div class="dataTable_wrapper">
                        <div id="dataTables-example_wrapper" class="dataTables_wrapper form-inline dt-bootstrap no-footer">
    			<!-- 分页搜索栏 -->
    						  <div class="row">
    						 
    				<form action="/admin/link/index" method="get">
                    <div class="col-sm-6">
                       <div class="dataTables_length" id="dataTables-example_length">
                         <label>每页
                         <select name="num" aria-controls="dataTables-example" class="form-control input-sm">
                             <option value="5">5</option>
                             <option value="15">15</option>
                             <option value="25">25</option>
                             <option value="50">50</option>
                         </select>条
                         </label>
                       </div>
                    </div>
    			    <div class="col-sm-6">
    				    <div id="dataTables-example_filter" class="dataTables_filter">
    				        <label>网站名:
    				          <input class="form-control input-sm" placeholder="" aria-controls="dataTables-example" type="search" name="keywords" value="{{$request['keywords'] or ''}}">&nbsp
    				          <button class="btn btn-primary">搜索</button>
    				        </label>
    				    </div>
    				    </div>
    			    </form>
    			  </div>
    			  <div class="row">
    			  
    <!-- 分页搜索栏end         -->
         
            
                    <div class="panel-body">
                            <div class="table-responsive">
                                <table class="table table-striped table-bordered table-hover">
            <!-- 字段开始 -->
                                    <thead>
                                        <tr>
                                            <th>ID</th>
                                            <th>站点名称</th>
                                            <th>站点地址</th>
                                            <th>状态</th>
                                            <th>email</th>
                                            <th>站点联系人</th>
                                            <th>操作</th>
                                        </tr>
                                    </thead>
            <!-- 字段开始end -->  
                                    <tbody>
            <!-- 循环体 -->
                                     @foreach($data as $k=>$v)
                                        <tr>
                                            <td class="sid">{{$v->id}}</td>
                                            <td>{{$v->linkname}}</td>
                                            <td>{{$v->linkaddress}}</td>
                                            <td>{{$status_list[$v->status]}}</td>
                                            <td>{{$v->email}}</td>
                                            <td>{{$v->linkmen}}</td>
                                            <td>
                                            <a class="delete">删除</a>
                                            &nbsp&nbsp&nbsp&nbsp
                                            <a href="/admin/link/edit/{{$v->id}}">编辑</a>
                                            </td>
                                        </tr>
                                    @endforeach
            <!-- 循环体end -->      
                                    </tbody>
                                </table>
                            </div>
                            <!-- /.table-responsive -->
                        </div>

                </table></div></div>
               

                <div class="row"><div class="col-sm-6">
                   <div class="dataTables_info" id="dataTables-example_info" role="status" aria-live="polite">
                   </div>
                </div>
                <div class="col-sm-6">
                     <div class="dataTables_paginate paging_simple_numbers" id="dataTables-example_paginate">
                        <ul class="pagination">
                            {!! $data->appends($request)->render() !!}
                        </ul>
                     </div>
                </div>
            </div>
            </div>
            </div>
            <!-- /.table-responsive -->
         
        </div>
        <!-- /.panel-body -->
       </div>
    <!-- /.panel -->
   </div>
@endsection
@section('myjs')
    <script type="text/javascript">
        //基于 AJAX 的应用，提供了简单、方便的 CSRF 保护
        $.ajaxSetup({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                }
        });
           //查找delete的id
           $('.delete').click(function(){
               //获取要删除的ID
               var id = $(this).parents('tr').find('.sid').html();
               //定义对象
               var dd = $(this);
               //发送ajax
               $.post('/admin/link/delete',{id:id},function(data){
                   if(data==1){
                    dd.parents('tr').remove();
                    alert('删除成功');
                   }else{
                    alert('删除失败');
                   }
               })
               // return false;
           });
    </script>
@endsection